package Monitors;


import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import static ProcessThread.util.Sleeper.sleep;

@Slf4j(topic = "c.EightLock")
public class EightLock {


    @Test
    public void test1(){
        Number1 n1 = new Number1();
            new Thread(() -> {
                n1.a();
            }).start();
            new Thread(() -> {
                n1.b();
            }).start();
    }
    @Test
    public void test2(){
        Number2 n1 = new Number2();
        new Thread(()->{ n1.a(); }).start();
        new Thread(()->{ n1.b(); }).start();
    }
    @Test
    public void test3(){
        Number3 n1 = new Number3();
        new Thread(()->{ n1.a(); }).start();
        new Thread(()->{ n1.b(); }).start();
        new Thread(()->{ n1.c(); }).start();
    }
    @Test
    public void test4(){
        Number4 n1 = new Number4();
        Number4 n2 = new Number4();
        new Thread(()->{ n1.a(); }).start();
        new Thread(()->{ n2.b(); }).start();
    }
    @Test
    public void test5(){
        Number5 n1 = new Number5();
        new Thread(()->{ n1.a(); }).start();
        new Thread(()->{ n1.b(); }).start();
    }
    @Test
    public void test6(){
        Number6 n1 = new Number6();
        new Thread(()->{ n1.a(); }).start();
        new Thread(()->{ n1.b(); }).start();
    }
    @Test
    public void test7(){
        Number7 n1 = new Number7();
        Number7 n2 = new Number7();
        new Thread(()->{ n1.a(); }).start();
        new Thread(()->{ n2.b(); }).start();
    }
    @Test
    public void test8(){
        Number8 n1 = new Number8();
        Number8 n2 = new Number8();
        new Thread(()->{ n1.a(); }).start();
        new Thread(()->{ n2.b(); }).start();
    }
}

@Slf4j(topic = "c.Number1")
class Number1{
    public synchronized void a() {
        log.debug("1");
    }
    public synchronized void b() {
        log.debug("2");
    }
}
@Slf4j(topic = "c.Number2")
class Number2{
    public synchronized void a() {
        sleep(1);
        log.debug("1");
    }
    public synchronized void b() {
        log.debug("2");
    }
}
@Slf4j(topic = "c.Number3")
class Number3{
    public synchronized void a() {
        sleep(1);
        log.debug("1");
    }
    public synchronized void b() {
        log.debug("2");
    }
    public void c() {
        log.debug("3");
    }
}
@Slf4j(topic = "c.Number4")
class Number4{
    public synchronized void a() {
        sleep(1);
        log.debug("1");
    }
    public synchronized void b() {
        log.debug("2");
    }
}
@Slf4j(topic = "c.Number5")
class Number5{
    public static synchronized void a() {
        sleep(1);
        log.debug("1");
    }
    public synchronized void b() {
        log.debug("2");
    }
}
@Slf4j(topic = "c.Number6")
class Number6{
    public static synchronized void a() {
        sleep(1);
        log.debug("1");
    }
    public static synchronized void b() {
        log.debug("2");
    }
}
@Slf4j(topic = "c.Number7")
class Number7{
    public static synchronized void a() {
        sleep(1);
        log.debug("1");
    }
    public synchronized void b() {
        log.debug("2");
    }
}
@Slf4j(topic = "c.Number8")
class Number8{
    public static synchronized void a() {
        sleep(1);
        log.debug("1");
    }
    public static synchronized void b() {
        log.debug("2");
    }
}
